<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SLessonInfo extends Model
{
    use SoftDeletes;
    public $table = "s_lesson_info";

    protected $fillable = [
        'user_id', 'teacher_id', 'cloud_id', 'lesson_type_id', 'begin_time', 'end_time', 'lesson_status', 'lesson_cancle', 'send_notice','evaluate_explain', 'exaluate_vivid', 'exaluate_expand','evaluate_advice', 'tea_entry_time', 'stu_entry_time', 'tea_stop_time', 'stu_stop_time', 'created_at', 'updated_at'
    ];

    public function users()
    {
        return $this->belongsTo('App\User', 'user_id');
    }

    public function teachers()
    {
        return $this->belongsTo('App\Models\STeacherInfo', 'teacher_id');
    }

    public function cloudLessons()
    {
        return $this->belongsTo('App\Models\SCloudLessonInfo', 'cloud_id');
    }

    public function lessonTypes()
    {
        return $this->belongsTo('App\Models\SLessonType', 'lesson_type_id');
    }


    static public function getUserLessons($user_id, $start, $end)
    {
        return self::where([
            ['user_id', $user_id],
            ['begin_time', '>',  $start],
            ['begin_time', '<',  $end],
        ])
        ->orderBy('begin_time', 'desc')
        ->get();
    }
}
